<template>
	<!-- 区域编辑 -->
	<div>
		<div class="edit-top">
			编辑信息
			<i class="el-icon-close" @click='cancel'></i>
		</div>
		<div class="edit-content">
			<div class="edit-title">区域信息</div>
			<div class="edit-item">
				<label>区域编码</label><input v-model="info.code" type="text" />
			</div>
			<div class="edit-item">
				<label>区域名称</label><input v-model="info.name" type="text" />
			</div>
			<div class="edit-item">
				<label>所属区域</label><select v-model="info.parentId">
					<option value="0" selected="selected"></option>
					<option v-for="item in dep_list" :value="item.id">{{item.name}}</option>
				</select>
			</div>

		</div>
		<div class="edit-bottom">
			<span @click='cancel'>取消</span>
			<el-button @click='save' type="primary">保存</el-button>
		</div>
	</div>
</template>

<script>
	import Global from '@/components/Global.vue'
	export default {
		props: ['id'],
		data() {
			return {
				dep_list: [],
				info: {
					name: '',
					code: '',
					parentId: 0,

				}
			}
		},
		mounted() {
			this.get_dep_list();
			this.get_info();
		},
		methods: {
			//获取详情
			get_info() {
				var self = this;
				this.$axios.get(this.$global.serverIp + 'admin/sysProvince/detail/' + this.id)
					.then(function(res) {
						if (res != '')
							self.info = res.data;
					})
			},
			//获取列表
			get_dep_list() {
				var self = this;
				this.$axios.post(this.$global.serverIp + 'admin/sysProvince/findPage', {
						"limit": "10000",
						"page": "1"
					})
					.then(function(res) {
						if (res != '') {
							self.dep_list = res.data.list;
						}

					})
			},
			//点击保存
			save() {
				if (this.info.name == "") {
					this.$popup.open('部门名称不能为空');
					return;
				}
				if (this.info.code == "") {
					this.$popup.open('部门编码不能为空');
					return;
				}
				var self = this;
				this.$axios.post(this.$global.serverIp + 'jianeng-admin/sysProvince/update', self.info)
					.then(function(res) {
						if (res != '') {
							self.success('编辑成功');
						}
					})
			},
			//添加成功
			success(content) {
				var self = this;
				this.$alert(content, '提示', {
					confirmButtonText: '确定',
					callback: action => {
						self.$emit("saveEdit", 2);
					}
				});
			},
			//点击取消
			cancel() {
				this.$emit("saveEdit", 1);
			}
		}
	}
	import '@/assets/css/edit.css'
</script>
